package org.acy.file.util;

import org.apache.commons.lang3.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {

    /**
     * 获取指定日期的23点59分59秒
     *
     * @return date
     */
    public static Date getNightDate(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        return calendar.getTime();
    }


    /**
     * 获取指定日期的0点0分0秒
     *
     * @return date
     */
    public static Date getZeroDate(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        return calendar.getTime();
    }

    public static Date getFormatDate(String date) {
        String format = "yyyy-MM-dd";

        SimpleDateFormat sd = new SimpleDateFormat(format);
        Date rtnDate = null;

        try {
            date = date.replaceAll("/", "-");
            rtnDate = sd.parse(date);
        } catch (ParseException var5) {
            var5.printStackTrace();
        }

        return rtnDate;
    }

    public static Date getAfterDay(Date dNow, int days) {
        Date dBefore;
        Calendar calendar = Calendar.getInstance(); // 得到日历
        calendar.setTime(dNow);// 把当前时间赋给日历
        calendar.add(Calendar.DAY_OF_MONTH, days); // 设置为前一天
        dBefore = calendar.getTime(); // 得到前一天的时间
        return dBefore;
    }
}
